package com.cy.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cy.common.exception.ServiceException;
import com.cy.common.vo.GoodsList;
import com.cy.common.vo.IndexSlider;
import com.cy.common.vo.PageObject;
import com.cy.dao.SysGoodsListDao;
import com.cy.dao.SysIndexDao;
import com.cy.entity.SysGoodsInfo;
import com.cy.service.SysIndexService;

/**  
 * @Title:  SysIndexServiceImpl.java   
 * @Package com.cy.service.impl   
 * @Description:    描述   
 * @author: ZHANGSIMIN     
 * @date:   2019年10月22日 下午5:31:56   
 * @version V1.0 
 */
@Service
public class SysIndexServiceImpl implements SysIndexService{
	
	@Autowired
	private SysIndexDao sysIndexDao;
	
	@Autowired
	private SysGoodsListDao sysGoodsListDao;

	@Override
	public List<IndexSlider> getIndexSlider() {
		return sysIndexDao.getIndexSlider();
	}

	@Override
	public PageObject<GoodsList> getIndexGoods(Integer type) {
		PageObject<GoodsList> result = new PageObject<GoodsList>();
		List<SysGoodsInfo> list;
		if(type == 1) {
			list = sysIndexDao.getIndexGoodsByNews();
		}else if(type == 2) {
			list = sysIndexDao.getIndexGoodsBySales();
		}else {
			throw new ServiceException("服务器炸了");
		}
		List<GoodsList> goodsList = new ArrayList<>();
		for(SysGoodsInfo info : list) {
			GoodsList item = new GoodsList();
			int itemid = info.getId();
			double basePrice = sysGoodsListDao.getGoodsBasePrice(itemid);
			String imgUrl = sysGoodsListDao.getGoodsListImg(itemid);
			item.setGoodsId(itemid);
			item.setGoodsName(info.getGoods_name());
			item.setBasePrice(basePrice);
			item.setImgUrl(imgUrl);
			goodsList.add(item);
		}
		result.setRecords(goodsList);
		return result;
	}

}
